﻿@model CmsAdminPageModel

@{
    Layout = "~/admin/Templates/TelerikAdministration.cshtml";
    ResFile = "cms_Pages";
    ViewBag.Title = _("Add new page");
}

<p><a class="b-back-link" href="/admin/cmspage"><i class="b-icon"></i> @_("Back to pages")</a></p>

<h1 class="g-clear">
	<i class="b-icon b-icon_h b-icon_h_pages"></i>
	<span class="b-overflow">
		@_("Add new page")
	</span>  
</h1>

@{Html.RenderPartial("ErrorPanel");}
<fieldset class="b-form">
@using (Html.BeginForm("add", "cmspage"))
{
    <ol class="b-form__rows ul-reset g-clear">
        <li class="b-form__row g-clear">
            <label for="PageName">@_("Page Title")</label>
            @Html.TextBoxFor(p => p.PageName, new { @class = "text" })
            @Html.ValidationMessageFor(p => p.PageName)
        </li>
        <li class="b-form__row g-clear b-form__row_masked">
            <label for="ParentPageId">@_("Parent page")</label>
            @Html.TextBoxFor(p => p.ParentPageName, new { @class = "text" })
            @Html.HiddenFor(p => p.ParentPageId, new { @class = "text rel-property" })                    
            @{Html.RenderPartial("FileViewDialog", new CmsFileViewModel { DialogFor = "Page", TargetId = "ParentPageName, ParentPageId" });}
        	<div class="b-text-mask"></div>
        </li>
        <li class="b-form__row g-clear">
            <label for="BehaviourPageType">@_("Page type")</label>
            @Html.DropDownListFor(p => p.BehaviourPageType, new SelectList(Model.PageTypeList, "Value", "Text"), new { @class = "js-select-show-hide", data_container=".js-page-type" })
        </li>
        <li class="b-form__row g-clear js-page-type js-redirect">
            <label for="RedirectType">@_("Redirect type")</label>
            @Html.DropDownListFor(p => p.RedirectType, new SelectList(Model.RedirectTypes, "Value", "Text"))
        </li>
        <li class="b-form__row g-clear b-form__row_masked js-page-type js-content js-redirect">
            <label for="PageUrl">@_("Page url")</label>
            <input type="text" class="text" id="PageUrl" name="PageUrl" />
            <div class="b-text-mask b-text-mask-page-url"></div>
            <button id="pageUrl-edit" type="button" class="b-button b-button_small">@_("Edit")</button>
            <button id="pageUrl-cancel" type="button" class="b-button b-button_small b-button_colour_grey hide">@_("Cancel")</button>
            @Html.ValidationMessageFor(p => p.PageUrl)
        </li>
        <li class="b-form__row g-clear js-page-type js-redirect">
            <label for="RedirectUrl">@_("Redirect Url")</label>
            @Html.TextBoxFor(p => p.RedirectUrl, new { @class = "text" })
            @Html.ValidationMessageFor(p => p.RedirectUrl)
        </li>
        <li class="b-form__row g-clear js-page-type js-redirect">
        @_("or")
        </li>
        <li class="b-form__row g-clear b-form__row_masked js-page-type js-redirect">
            <label for="PageName">@_("Redirect to page")</label>
            @Html.TextBoxFor(p => p.RedirectPageName, new { @class = "text" })
            @Html.HiddenFor(p => p.RedirectPageId, new { @class = "text rel-property" })                    
            @{Html.RenderPartial("FileViewDialog", new CmsFileViewModel{ DialogFor = "Page", TargetId = "RedirectPageName, RedirectPageId" });}
        	<div class="b-text-mask"></div>
        </li>
        <li class="b-form__row g-clear js-page-type js-redirect">
            <label for="RedirectOpenInNewWindow">@_("Open in new window")</label>
            @Html.CheckBoxFor(p => p.RedirectOpenInNewWindow)            
        </li>                 
        <li class="b-form__row g-clear js-page-type js-content">
            <label for="TemplateList">@_("Use template")</label>
            @Html.DropDownListFor(p => p.TemplateId, new SelectList(Model.TemplateList, "Value", "Text", Model.TemplateId))
        </li>
        <li class="b-form__row g-clear">
            <label for="IsVisible">@_("Visible on navigation bar")</label>
            @Html.CheckBoxFor(p => p.IsVisible)
        </li> 
        @if (!CmsConfiguration.IsWorkflowEnabled)
        {
        <li class="b-form__row g-clear">
            <label for="IsPublished">@_("Published")</label>
            @Html.CheckBoxFor(p => p.IsPublished)
        </li>
        <li class="b-form__row g-clear">
            <label for="PublishStartDate">@_("Publish from")</label>
            @(Html.Telerik().DatePicker()
                .Name("PublishStartDate")
                .InputHtmlAttributes(new { @class = "text b-text_date" }) 
                .ShowButton(true))
        </li>
        <li class="b-form__row g-clear">
            <label for="PublishEndDate">@_("Publish to")</label>
            @(Html.Telerik().DatePicker()
                .Name("PublishEndDate")
                .InputHtmlAttributes(new { @class = "text b-text_date" }) 
                .ShowButton(true))
        </li>
        }
        <li class="b-form__row g-clear">
        </li>
        <li class="b-form__row b-form__row_buttons g-clear">
        	<input class="b-button" id="btnSave" name="btnSave" type="submit" value="@_("Add")" />
        </li>        
    </ol> 
}	
</fieldset>

@section scriptBlock{    
    <script type="text/javascript">
    // <![CDATA[
        $(document).ready(function () {
            var $elUrl = $('#PageUrl');
            $('#PageName').bind('keydown input', function () {
                var val = $(this).val().trim().replace(new RegExp(" ", 'g'), "-");
                if (!val.startsWith('/')) {
                    val = '/' + val;
                }
                if ($elUrl.is(":visible")) {
                    $elUrl.val(val.toLowerCase());
                }
                else {
                    $elUrl.val("");
                }
            });
        });
    // ]]>
    </script>
}